/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.general.bc;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.cip.esymons.general.be.Igv;
import oracle.toplink.essentials.config.HintValues;
import oracle.toplink.essentials.config.TopLinkQueryHints;
/**
 *
 * @author Lizardo Rios
 */
@Stateless
public class IgvFacade implements IgvFacadeLocal {
    @PersistenceContext
    private EntityManager em;

    public void create(Igv igv) {
        em.persist(igv);
    }

    public void edit(Igv igv) {
        em.merge(igv);
    }

    public void remove(Igv igv) {
        em.remove(em.merge(igv));
    }

    public Igv find(Object id) {
        return em.find(Igv.class, id);
    }

    public List<Igv> findAll() {
        return em.createQuery("select i from Igv i").getResultList();
    }

    public Igv igvVigente() {
        try {
            return (Igv)em.createQuery("select i from Igv i where i.igvHabilitado = true").setHint(TopLinkQueryHints.REFRESH, HintValues.TRUE).getSingleResult();
        } catch (Exception ex) {
            return null;
        }
    }
     
}
